import React, { Component } from 'react'
import PubSub from 'pubsub-js'
import axios from 'axios'
export default class Search extends Component {
  search=()=>{
// 获取用户输入的数据
const keyWord = this.keyWordElement.value
console.log(keyWord);
// 通知List组件改变数据
PubSub.publish('isMe',{isFirst:false,isLoading:true})// 发布消息
axios.get('http://localhost:3000/api1/search/users2?q='+keyWord).then((res)=>{
console.log(res.data.items);
// 通知List组件改变数据
PubSub.publish('isMe',{isLoading:false,users:res.data.items})
}).catch((err)=>{
  // 通知List组件改变数据
  PubSub.publish('isMe',{isLoading:false,err:err.message})

})
  }
  render() {
    return (
        <section className="jumbotron">
        <h3 className="jumbotron-heading">搜索用户</h3>
        <div>
          <input type="text" placeholder="请输入" ref={c => this.keyWordElement = c} />&nbsp;<button onClick={this.search}>搜索</button>
        </div>
      </section>
    )
  }
}
